package com.wisdytech.linkdcs.equipLifeCycle.malfunction.action;


import com.wisdytech.common.handler.ResourceMatchingService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.dto.MalfunctionSearchDto;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MApplyRecord;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MProcessRecord;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.IMApplyRecordService;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.vo.MalfunctionApplyVO;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.vo.MalfunctionVo;
import com.wisdytech.linkdcs.system.model.SysUser;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenbin
 * @since 2018-07-25
 */
@Controller
@RequestMapping("/equipLifeCycle/malfunction/mApplyRecord")
public class MApplyRecordAction {

    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
	@RequestMapping("/index")
	public String recoreIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
		return "lifeCycle/equipLifeCycle/malfunction/apply";
	}
	
	@Autowired
	private IMApplyRecordService iMApplyRecordService;
	
	@RequestMapping("/addApplyRecord/add.mvc")
	@ResponseBody
	public StandardResult addApplyRecord(MApplyRecord applyRecord) {
		SysUser user =BaseUtil.getCurrentUser();
		return  iMApplyRecordService.addApplyRecord(applyRecord, user.getUsername())?
				StandardResult.getSuccessResult():
					StandardResult.getFailResult("保存失败");
	}
	
	@RequestMapping("/listApplyRecords/get.mvc")
	@ResponseBody
	public StandardTableResult<MalfunctionApplyVO> listRecords(Filter filter,MalfunctionSearchDto dto){
		
		PageInfo<MalfunctionApplyVO>  pageInfo =
				iMApplyRecordService.listApplyRecords(filter, dto);
		StandardTableResult<MalfunctionApplyVO> tables=
				new StandardTableResult<MalfunctionApplyVO>(pageInfo.getTotal(),pageInfo.getList());
		
		return tables;
	}
	
	/**
	 * 提交审批
	 * @param pkId
	 * @return
	 */
	@RequestMapping("/applyCommitOver/add.mvc")
	@ResponseBody
	public StandardResult applyCommitOver(String pkId) {
		iMApplyRecordService.applyCommitOver(pkId);
		return	StandardResult.getSuccessResult();
	}
	
	/**
	 * 提交审批
	 * @param pkId
	 * @return
	 */
	@RequestMapping("/applyReturnFactory/add.mvc")
	@ResponseBody
	public StandardResult applyReturnFactory(String pkId) {
		iMApplyRecordService.applyReturnFactory(pkId);
		return	StandardResult.getSuccessResult();
	}
		
}

